{% extends './layout/default' %}

{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, objectType, start, end) }}
{% endblock %}

{% block content %}

    {# upper show-all instruction #}
    {% if periods|length > 0 %}
        <div class="row">
            <div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
                <p class="small text-center"><a href="{{ route('transactions.index.all',[objectType]) }}">{{ 'showEverything'|_ }}</a></p>
            </div>
        </div>
    {% endif %}

    {% if periods|length > 0 %}

        {% set boxSize = 'col-lg-4 col-md-6 col-sm-12 col-xs-12' %}
        <div class="row">
            {# for withdrawals, deposits and transfers #}
            <div class="{{ boxSize }}">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'categories'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        <canvas id="category_chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
            {# only for withdrawals #}
            {% if objectType == 'withdrawal' %}
                <div class="{{ boxSize }}">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">{{ 'budgets'|_ }}</h3>
                        </div>
                        <div class="box-body">
                            <canvas id="budget_chart" style="width:100%;height:250px;" height="250"></canvas>
                        </div>
                    </div>
                </div>
            {% endif %}
            {% if objectType != 'withdrawal' %}
                <div class="{{ boxSize }}">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">{{ 'all_source_accounts'|_ }}</h3>
                        </div>
                        <div class="box-body">
                            <canvas id="source_chart" style="width:100%;height:250px;" height="250"></canvas>
                        </div>
                    </div>
                </div>
            {% endif %}
            {# for all #}
            <div class="{{ boxSize }}">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'all_destination_accounts'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        <canvas id="destination_chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    {% endif %}

    {# list with journals #}
    <div class="row">
        <div class="{% if periods|length > 0 %}col-lg-10 col-md-10 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ subTitle }}</h3>
                </div>
                <div class="box-body no-padding">
                    <div style="padding:8px;">
                        <a href="{{ route('transactions.create', [objectType]) }}" class="btn btn-success"><span class="fa fa-plus fa-fw"></span> {{ 'create_new_transaction'|_ }}</a>
                    </div>
                    {# actual list #}
                    {% include 'list.groups' %}
                </div>
                <div class="box-footer">
                    {# links for other views #}
                    {% if periods|length > 0 %}
                        <p>
                            <span class="fa fa-calendar"></span>
                            <a href="{{ route('transactions.index.all', [objectType]) }}">{{ 'show_all_no_filter'|_ }}</a>
                        </p>
                    {% else %}
                        <p>
                            <span class="fa fa-calendar"></span>
                            <a href="{{ route('transactions.index', [objectType]) }}">{{ 'show_the_current_period_and_overview'|_ }}</a>
                        </p>
                    {% endif %}
                </div>
            </div>
        </div>

        {# boxes with info #}
        {% if periods|length > 0 %}
            <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
                {% include 'list.periods' %}
            </div>
        {% endif %}

    </div>

    {# lower show-all instruction #}
    {% if periods|length > 0 %}
        <div class="row">
            <div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
                <p class="small text-center"><a href="{{ route('transactions.index.all', [objectType]) }}">{{ 'showEverything'|_ }}</a></p>
            </div>
        </div>
    {% endif %}

{% endblock %}
{% block scripts %}
    {# required for groups.twig #}
    <script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        var showAll = {% if periods|length > 0 %}false{% else %}true{% endif %};

        var categoryChartUrl = '{{ route('chart.transactions.categories', [objectType, start.format('Y-m-d'), end.format('Y-m-d')]) }}';
        var budgetChartUrl = '{{ route('chart.transactions.budgets', [start.format('Y-m-d'), end.format('Y-m-d')]) }}';
        var destinationChartUrl = '{{ route('chart.transactions.destinationAccounts', [objectType, start.format('Y-m-d'), end.format('Y-m-d')]) }}';
        var sourceChartUrl = '{{ route('chart.transactions.sourceAccounts', [objectType, start.format('Y-m-d'), end.format('Y-m-d')]) }}';

    </script>
    <script type="text/javascript" src="v1/js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/lib/chartjs-plugin-annotation.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/charts.defaults.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/charts.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>

    <script type="text/javascript" src="v1/js/ff/transactions/index.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
{% endblock %}
